package com.example.lianxi1;

import com.example.APP.App;
import com.example.xts.greendaodemo.db.AlbumsBeanDao;

import java.util.List;

public class DBUtil {
    public static List<AlbumsBean> getAll(){

        return App.daoSession.loadAll(AlbumsBean.class);
    }

    public static long insert(AlbumsBean albumsBean) {
        AlbumsBean eixst = isEixst(albumsBean);
        //当前对象不存在
        if (eixst == null) {
            return    App.daoSession.insert(albumsBean);
        }
        return -1;
    }

    /**
     * 判断当前对象是否存在
     *
     * @param albumsBean
     * @return
     */
    public static AlbumsBean isEixst(AlbumsBean albumsBean) {

        AlbumsBean bean = App.daoSession.queryBuilder(AlbumsBean.class)
                .where(AlbumsBeanDao.Properties.Id.eq(albumsBean.getId())).unique();

        return bean == null ? null : bean;
    }
}
